package leetcode.t5Stack;

import java.util.Stack;

/**
 * @author K
 * @date 2024/1/17 13:44
 */
public class StackSolution {
    public static void main(String[] args) {
        String[] strings = {"4", "13", "5", "/", "+"};
        Stack<String> stack = new Stack<>();
        String operators = "+-*/";
        for (String e : strings) {
            if (operators.contains(e)) {
                Integer a = Integer.valueOf(stack.pop());
                Integer b = Integer.valueOf(stack.pop());
                switch (e){
                    case "+":
                        stack.push(String.valueOf(a + b));
                        break;
                    case "-":
                        stack.push(String.valueOf(b - a));
                        break;
                    case "*":
                        stack.push(String.valueOf(a * b));
                        break;
                    case "/":
                        stack.push(String.valueOf(b / a));
                        break;
                }

            } else {
                stack.push(e);
            }
        }

        String peek = stack.peek();
        System.out.println();
    }
}
